import 'school_model.dart' show Voice, Photo;
class ArtcleReplyListModel {
  int id;
  String title;
  String content;
  int replys;
  int createtime;
  int updatetime;
  String username;
  String mobile;
  String avatar;
  String schoolname;
  List<ReplyModel> reply;
  List<Photo> photo;
  String bio;
  Voice voice;

  int upvotes;  // 赞
  int reports; // 转发

  int followflag; // 是否关注
  String followRemark; // 备注名称
  int upvoteflag; //是否点赞.

  // 获取用户显示的名称
  String get remarkname {
    if(username == null && followRemark == null) return mobile;
    return followRemark == null ? username : followRemark;
  }

  ArtcleReplyListModel(
      {this.id,
      this.title,
      this.content,
      this.replys,
      this.createtime,
      this.updatetime,
      this.username,
      this.mobile,
      this.avatar,
      this.schoolname,
      this.photo,
      this.voice,
      this.bio,
      this.upvotes,
      this.reports,
      this.followflag,
      this.followRemark,
      this.upvoteflag,
      this.reply});

  ArtcleReplyListModel.fromJson(Map<String, dynamic> json) {
    id = json['id'];
    title = json['title'];
    content = json['content'];
    createtime = json['createtime'];
    updatetime = json['updatetime'];
    username = json['username'];
    mobile = json['mobile'];
    avatar = json['avatar'];
    bio = json['bio'];
    schoolname = json['schoolname'];
    upvotes = json['upvotes'];
    replys = json['replys'];
    reports = json['reports'];

    followflag = json['followflag'];
    followRemark = json['follow_remark'];
    upvoteflag = json['upvoteflag'];

    if (json['reply'] != null) {
      reply = new List<ReplyModel>();
      json['reply'].forEach((v) {
        reply.add(new ReplyModel.fromJson(v));
      });
    }
    if (json['photo'] != null) {
      photo = new List<Photo>();
      json['photo'].forEach((v) {
        photo.add(new Photo.fromJson(v));
      });
    }
    voice = json['voice'] != null ? new Voice.fromJson(json['voice']) : null;
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['id'] = this.id;
    data['title'] = this.title;
    data['content'] = this.content;
    data['replys'] = this.replys;
    data['createtime'] = this.createtime;
    data['updatetime'] = this.updatetime;
    data['username'] = this.username;
    data['mobile'] = this.mobile;
    data['avatar'] = this.avatar;
    data['schoolname'] = this.schoolname;
    if (this.reply != null) {
      data['reply'] = this.reply.map((v) => v.toJson()).toList();
    }
    return data;
  }
}

class ReplyModel {
  String content;
  int createtime;
  int updatetime;
  String username;
  String mobile;
  String avatar;
  String schoolname;
  String callname; // 回复者的名字
  String bio;
  int upvotes;
  int replys;
  int id;
  List<ReplyModel> reply;
  Voice voice;
  List<Photo> photo;
  
  int followflag;
  String followRemark; // 备注名称
  int upvoteflag; //是否点赞.
  int dissflag;

  String get strUpvotes {
    return _complute(this.upvotes);
  }

  String get strReplys {
    return _complute(this.replys);
  }

  String _complute(int count) {
    if(count == null) return "0";
    return count > 9999 ? ((count / 10000.0).toStringAsFixed(1) + "w") : count.toString();
  }

  // 获取用户显示的名称
  String get remarkname {
    if(username == null && followRemark == null) return mobile;
    return followRemark == null ? username : followRemark;
  }

  ReplyModel(
      {this.content,
      this.createtime,
      this.updatetime,
      this.username,
      this.mobile,
      this.avatar,
      this.schoolname,
      this.upvotes,
      this.replys,
      this.voice,
      this.callname,
      this.photo,
      this.id,
      this.reply,
      this.dissflag,
      this.upvoteflag
  });

  ReplyModel.fromJson(Map<String, dynamic> json) {
    content = json['content'];
    createtime = json['createtime'];
    updatetime = json['updatetime'];
    username = json['username'];
    mobile = json['mobile'];
    avatar = json['avatar'];
    callname = json['callname'];
    id = json['id'];
    schoolname = json['schoolname'];
    bio = json['bio'];
    upvotes = json['upvotes'];
    replys = json['replys'];

    followflag = json['followflag'];
    followRemark = json['follow_remark'];
    upvoteflag = json['upvoteflag'];
    dissflag = json['dissflag'];

    if (json['reply'] != null) {
      reply = new List<ReplyModel>();
      json['reply'].forEach((v) {
        reply.add(new ReplyModel.fromJson(v));
      });
    }

    voice = json['voice'] != null ? new Voice.fromJson(json['voice']) : null;
    if (json['photo'] != null) {
      photo = new List<Photo>();
      json['photo'].forEach((v) {
        photo.add(new Photo.fromJson(v));
      });
    }
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['content'] = this.content;
    data['createtime'] = this.createtime;
    data['updatetime'] = this.updatetime;
    data['username'] = this.username;
    data['mobile'] = this.mobile;
    data['avatar'] = this.avatar;
    data['schoolname'] = this.schoolname;
    data['upvotes'] = this.upvotes;
    data['replys'] = this.replys;
    data['bio'] = this.bio;
    data['callname'] = this.callname;
    data['id'] = this.id;
    if (this.reply != null) {
      data['reply'] = this.reply.map((v) => v.toJson()).toList();
    }
    if (this.voice != null) {
      data['voice'] = this.voice.toJson();
    }
    if (this.photo != null) {
      data['photo'] = this.photo.map((v) => v.toJson()).toList();
    }
    return data;
  }
}